﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using GWEB.WebBase.Entity;
using GWEB.WebBase.Utility;
using GWEB.WebFrame.Public;

namespace GWEB.WebFrame.Models
{
    public class Customer
    {
        public PageInfo Init()
        {
            PageInfo pg = new PageInfo();
            HttpSessionState session =System.Web.HttpContext.Current.Session;
            pg.dict = BasePage.getDict(session);
            pg.Type = "Customer";
            pg.ConditionColumn = 2;
            pg.Title = "客户管理";
            pg.AddText = "客户增加";
            pg.EditText = "客户修改";          
            pg.LocateText = "客户信息查询";
            pg.SMenuId = "CS05";
            pg.FileUrl = "";
            pg.Condition = "";
            pg.TableName = "cu_Customers";
            pg.KeyFieldName = "id";
            pg.PopEditHeight = 500;
            pg.PopEditWidth = 700;
            pg.Sop = BasePage.Grant(session, pg.SMenuId);

            pg.Sop.ADD = false; pg.Sop.EDIT = false;pg.Sop.DEL = false;

            pg.Button.Add("<li onclick=\"ShowModalUrlFull('popEdit', '../Customer/Create', '创建', '')\" class='layui-btn layui-btn-normal'><i class='layui-icon layui-icon-add-1'></i>创建</li>");            
            pg.Button.Add("<li onclick=\"ShowModalUrl('popEdit', '../Customer/Import', '导入', '', 700, 500)\" class='layui-btn layui-btn-normal'><i class='iconfont icon-daoru'></i>导入</li>");
            pg.Button.Add("<li onclick=\"ShowModalUrl('popEdit', '../Customer/Distribution', '分配', '', 700, 500)\" class='layui-btn layui-btn-normal'><i class='iconfont icon-icon-p_gongyingshangfenpei'></i>分配</li>");
            pg.Button.Add("<li onclick=\"ShowModalUrl('popEdit', '../Customer/Receive', '领取', '', 700, 500)\" class='layui-btn layui-btn-normal'><i class='iconfont icon-lingqukehu'></i>领取</li>");
            pg.Button.Add("<li onclick=\"ShowModalUrl('popEdit', '../Customer/Followup', '跟进', '', 700, 500)\" class='layui-btn layui-btn-normal'><i class='iconfont icon-mingdangenjin'></i>跟进</li>");
            pg.Button.Add("<li onclick=\"ShowModalUrl('popEdit', '../Customer/Sign', '签约', '', 700, 500)\" class='layui-btn layui-btn-normal'><i class='iconfont icon-qianyue'></i>签约</li>");
            
            pg.Tab.Add("待分配<span class='layui-badge'>99+</span>", "LocatePara='';DataPageUrl='../Main/DataPageLay?type=Customer&state=0';GoPage(1);");
            pg.Tab.Add("待领取<span class='layui-badge'>99+</span>", "LocatePara='';DataPageUrl='../Main/DataPageLay?type=Customer&state=1';GoPage(1);");
            pg.Tab.Add("待跟进<span class='layui-badge'>99+</span>", "LocatePara='';DataPageUrl='../Main/DataPageLay?type=Customer&state=2';GoPage(1);");
            pg.Tab.Add("待签约<span class='layui-badge'>99+</span>", "LocatePara='';DataPageUrl='../Main/DataPageLay?type=Customer&state=3';GoPage(1);");
            pg.Tab.Add("今日到访<span class='layui-badge'>99+</span>", "LocatePara='';DataPageUrl='../Main/DataPageLay?type=Customer&state=4';GoPage(1);");
            pg.Tab.Add("新会员<span class='layui-badge'>99+</span>", "LocatePara='';DataPageUrl='../Main/DataPageLay?type=Customer&state=5';GoPage(1);");
            pg.Tab.Add("老会员<span class='layui-badge'>99+</span>", "LocatePara='';DataPageUrl='../Main/DataPageLay?type=Customer&state=6';GoPage(1);");
            pg.Tab.Add("历史客户<span class='layui-badge'>99+</span>", "LocatePara='';DataPageUrl='../Main/DataPageLay?type=Customer&state=7';GoPage(1);");
            pg.Tab.Add("合同未审核通过<span class='layui-badge'>99+</span>", "LocatePara='';DataPageUrl='../Main/DataPageLay?type=Customer&state=8';GoPage(1);");

            HttpRequest request = System.Web.HttpContext.Current.Request;
            String state = Fun.cString(request["state"]);
            pg.Condition = " and custState=" + state;

            pg.Sql = @"
select * from (
select id,custName,childName,datediff(m,BirdDate,getdate()) custMonth,linkName,custTel,custState,t2.dname custStateCn,latelyFoupDate,custFrom,custRemark,'' link
from cu_Customers t1
left
join tb_sys_dictionary t2 on t1.CustState = t2.did and t2.typeid = 'D01'
) cu_Customers where 1=1";
            ColumnInfo cl;
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "custName"; cl.HeadText = "宝宝姓名"; cl.IsCondition = true; cl.ConditionPosition = 1; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "childName"; cl.HeadText = "宝宝小名"; cl.IsCondition = true; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Decimal; cl.FieldName = "custMonth"; cl.HeadText = "月龄"; cl.IsCondition = true; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "linkName"; cl.HeadText = "家长姓名"; cl.IsCondition = true;  pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "custTel"; cl.HeadText = "联系电话"; cl.IsCondition = true; cl.ConditionPosition = 1; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "custState"; cl.HeadText = "状态"; cl.IsCondition = true; cl.Visible = false; cl.DictTypeID = "D01"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "custStateCn"; cl.HeadText = "状态";  pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.DateTime; cl.FieldName = "latelyFoupDate"; cl.HeadText = "最近跟进时间"; cl.IsCondition = true; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "custFromId"; cl.HeadText = "渠道来源"; cl.IsCondition = true; cl.ConditionPosition = 1;cl.DictTypeID = "D03"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "custFrom"; cl.HeadText = "渠道来源"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "custRemark"; cl.HeadText = "备注"; cl.IsCondition = true; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "link"; cl.HeadText = "操作"; cl.IsSort = false; cl.Script = "<a href=\"javascript:ShowModalUrl('popEdit', '../Customer/Edit?id=[id]&keyCode='+GetKeyCode([id]), '详情', '', 700, 500)\" class='layui-btn layui-btn-primary layui-btn-xs'>详情</a><a href=\"javascript:ShowModalUrl('popEdit', '../Customer/More?id=[id]&keyCode='+GetKeyCode([id]), '补充', '', 700, 500)\" class='layui-btn layui-btn-xs'>补充</a>"; pg.AddColumn(cl);
            
            return pg;
        }
    }
}